﻿using System;
using System.Reflection;

namespace Rubik.Tester
{
    /// <summary>
    /// Represents the solution loader.
    /// </summary>
    public class RubikSolutionLoader
    {
        /// <summary>
        /// Loads the specified assembly.
        /// </summary>
        /// <param name="assembly">The assembly.</param>
        /// <returns>The solution activator.</returns>
        public RubikSolutionActivator Load(Assembly assembly)
        {
            foreach (Type type in assembly.GetTypes())
            {
                Type interfaceType = type.GetInterface("ICubeSerializer");
                if (interfaceType != null)
                {
                    return new RubikSolutionActivator(type);
                }
            }
            throw new ApplicationException("The specified assembly doesn't contain an implementation of ICubeSerializer interface");
        }
    }
}
